package com.dek.ssm.ch19;

import java.util.List;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.Pipeline;

public class PipelineTest {
	
	
	public static void main(String[] args) {
		JedisPool jedisPool = new JedisPool("localhost");
		try(Jedis jedis = jedisPool.getResource()) {
			long start = System.currentTimeMillis();
			Pipeline pipeline = jedis.pipelined();
			for (int i = 0; i < 100000; i++) {
				int j = i + 1;
				pipeline.set("pipeline_key_" + j, "pipeline_value" + j);
				pipeline.get("pipeline_key_" + j);
			}
			//pipeline.sync();//这里只执行同步，但是不返回结果
			//pipeline.syncAndReturnAll() ; 将返回执行过的命令返回的 List 列表结果
			List result = pipeline.syncAndReturnAll();
			long end = System.currentTimeMillis();
			System.out.println("耗时： " + (end - start) + "毫秒");
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
}
